import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:zhou_po/assets/color.dart';
import 'package:zhou_po/assets/myInkwell.dart';
import 'package:zhou_po/page/webview.dart';

class HomeInfoCard extends StatefulWidget {
  String title;
  String date;
  String imgUrl;
  String linkUrl;
  HomeInfoCard({
    super.key,
    required this.title,
    required this.date,
    required this.imgUrl,
    required this.linkUrl,
  });

  @override
  State<HomeInfoCard> createState() => _HomeInfoCardState();
}

class _HomeInfoCardState extends State<HomeInfoCard> {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(left: 10, top: 10, right: 10),
      child: myInkWell(
        tap: () {
          Navigator.of(context).push(MaterialPageRoute(
            builder: (context) {
              return OSWebViewPage(url: widget.linkUrl);
            },
          ));
        },
        color: os_white,
        radius: 10,
        widget: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10),
          ),
          padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
          child: Row(
            children: [
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      height: 45,
                      child: Text(
                        widget.title,
                        maxLines: 2,
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          fontSize: 15,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                    ),
                    Text(
                      widget.date,
                      style: TextStyle(
                        fontSize: 14,
                        color: Colors.grey[600],
                      ),
                    ),
                  ],
                ),
              ),
              Container(width: 5),
              ClipRRect(
                borderRadius: BorderRadius.circular(5),
                child: CachedNetworkImage(
                  imageUrl: widget.imgUrl,
                  width: 80,
                  height: 80,
                  fit: BoxFit.cover,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
